<?php
class UserSavePersonalAction extends UserAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	
	public function execute()
	{
		$this->code		= 0;
		$email			= strip_tags(trim($this->context->post('email')));
		$introduce		= strip_tags(trim($this->context->post('introduce')));
		$gender			= intval($this->context->post('gender'));
		$gender			= $gender==1 ? 1 : 0;
		$userService	= new BaseDbService('user');
		$update			= array();
		if ($email)
		{
			$tmp	= $userService->count(array('email'=>'eq:'.$email));
			if($tmp)
			{
				$this->data['error_messages']['email']	= array('lower'=>'该邮箱已经被其他用户使用');
			}
			else
			{
				$update['email'] = $email;
			}
		}
		$update['introduce'] 	= $introduce;
		$update['gender'] 		= $gender;
		if(empty($this->data['error_messages']))
		{
			$userService->update($this->data['user']['id'], $update);
			$this->code	= 200;
			$this->data['forward'] = C('LtUrl')->generate('User', 'Set', array('type'=>'personal'));
		}
	}
}
